//
//  YYHTTPClient.swift
//  SinaWeibo
//
//  Created by Apple on 16/5/6.
//  Copyright © 2016年 devshaw. All rights reserved.
//

import UIKit
import AFNetworking




 // MARK: - 枚举
enum YYHTTPClientType:String{
    case POST = "POST"
    case GET = "GET"
}


//enum 枚举名: 类型{
        //case
        //case
//}



class YYHTTPClient: AFHTTPSessionManager {


    //Swift单列
    //static 修饰的变量在静态区
    static let shareInstance: YYHTTPClient = {


    let client = YYHTTPClient()

    client.responseSerializer.acceptableContentTypes?.insert("text.plain")

    //网络工具类创建网络请求的方法   pod search  3.0 最新版本
//    override func POST(URLString: String, parameters: AnyObject?, progress uploadProgress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) -> NSURLSessionDataTask? {
//        <#code#>
//    }

//    override func GET(URLString: String, parameters: AnyObject?, progress downloadProgress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) -> NSURLSessionDataTask? {
//        <#code#>
//    }
        return client
    }()
    func  requset(type:YYHTTPClientType,URLString: String, parameters: AnyObject?,  success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){

        YYHTTPClient.shareInstance.request(type, URLString: URLString, parameters: parameters, progress: nil, success: success, failure: failure)

        }


    func request(type: YYHTTPClientType,URLString: String, parameters: AnyObject?, progress downloadProgress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){

    func  requset(type:YYHTTPClientType){
        //需要请求一下请求方法
        if type == .GET{

            self.GET(URLString, parameters: parameters, progress: downloadProgress, success: success, failure: failure)
        }else if type == .POST {

            self.POST(URLString, parameters: parameters, progress: downloadProgress, success: success, failure: failure)
        }
    }
}
}